/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package guiforms;

import controlers.MainControler;


/**
 *
 * @author Tasos
 */
public class MainScreen extends javax.swing.JFrame {
private String customerID = "";
private MainControler ctrl = new MainControler();
    /**
     * To kentriko menou pelath
     */
    public MainScreen() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnBuy = new javax.swing.JButton();
        btnManageMyAccount = new javax.swing.JButton();
        btnReturnToLogin = new javax.swing.JButton();
        jtxtfWellcomeMessage = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnBuy.setText("Αγορά προιόντων");
        btnBuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuyActionPerformed(evt);
            }
        });

        btnManageMyAccount.setText("Διαχείριση Προφίλ");
        btnManageMyAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManageMyAccountActionPerformed(evt);
            }
        });

        btnReturnToLogin.setText("Επιστροφή στην Οθόνη Εισόδου");
        btnReturnToLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReturnToLoginActionPerformed(evt);
            }
        });

        jtxtfWellcomeMessage.setEditable(false);
        jtxtfWellcomeMessage.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtxtfWellcomeMessage.setText("Wellcome Message");
        jtxtfWellcomeMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtfWellcomeMessageActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnBuy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnManageMyAccount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnReturnToLogin))
                .addContainerGap(40, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtxtfWellcomeMessage)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtxtfWellcomeMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnBuy, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnManageMyAccount, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnReturnToLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnBuy.getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

 

//Event Handler toy Button Agorwn
    private void btnBuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuyActionPerformed
//nea forma Agorwn
BuyProductsScreen bs=new BuyProductsScreen();
//enhmerwsh ths me to Customer ID
bs.setCustomerID(customerID);
//Provolh
bs.setVisible(true);
//katastrofh ths parousas formas
this.dispose();
    }//GEN-LAST:event_btnBuyActionPerformed

    //Event Handler tou Epistrofh sthn LOgin Screen
    private void btnReturnToLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReturnToLoginActionPerformed
    //nea Login Forma
    LoginForm lf = new LoginForm();
    lf.setVisible(true);
    //katastrofh ths parousas formas
    this.dispose();
    }//GEN-LAST:event_btnReturnToLoginActionPerformed

    //Event Handler toy koumipou diaxeirishs Profile
    private void btnManageMyAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManageMyAccountActionPerformed
        //nea ManageMyProfile forma
        ManageMyProfile mp = new ManageMyProfile();
        //enhmerwsh ths me ton Customer ID
        mp.setCustomerID(customerID);
        //Provolh
        mp.setVisible(true);
        //katastrofh parousas
        this.dispose();
    }//GEN-LAST:event_btnManageMyAccountActionPerformed

    private void jtxtfWellcomeMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtfWellcomeMessageActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtfWellcomeMessageActionPerformed

    
//thetei to Customer ID kai enhmerwnei to pedio kalwsorismatos toy pelath    
public void setCustomerID(String cid)
{
customerID=cid;
//Xrhsh toy MainControler gia fetch stoixeiwn pelath
MainControler ctrl = new MainControler();
//enhmervsh pediou welcome
jtxtfWellcomeMessage.setText("Welcome Mr/Mrs " + ctrl.findCustomerByCard(cid).getLastName() +" "+ctrl.findCustomerByCard(cid).getFirstName());
}        
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainScreen().setVisible(true);
            }
        });
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuy;
    private javax.swing.JButton btnManageMyAccount;
    private javax.swing.JButton btnReturnToLogin;
    private javax.swing.JTextField jtxtfWellcomeMessage;
    // End of variables declaration//GEN-END:variables
}
